package cn.bugstack.domain.strategy.model.entity;

import cn.bugstack.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 策略规则实体类
 */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StrategyRuleEntity {

    //抽奖策略ID
    private Long strategyId;
    //抽奖奖品ID【规则类型为策略，则不需要奖品ID】
    private Integer awardId;
    //抽象规则类型；1-策略规则、2-奖品规则
    private Integer ruleType;
    //抽奖规则类型【rule_random - 随机值计算、rule_lock - 抽奖几次后解锁、rule_luck_award - 幸运奖(兜底奖品)
    private String ruleModel;
    //抽奖规则比值
    private String ruleValue;
    //抽奖规则描述
    private String ruleDesc;

    //获取rule_weight 的 所有 rule_value， 存放入Map集合里
    //数据格式：
    //ruleValue = "4000:102,103,104,105 5000:102,103,104,105,106,107 6000:102,103,104,105,106,107,108,109"
    public Map<String, List<Integer>> getRuleWeightValues(){
        if(!"rule_weight".equals(ruleModel)){
            return null;
        }
        Map<String, List<Integer>> stringListHashMap = new HashMap<>();
        String[] ruleValues = ruleValue.split(Constants.SPACE);
        for(String ruleValue : ruleValues){
            String[] parts = ruleValue.split(Constants.COLON);
            String[] valueStrings = parts[1].split(Constants.SPLIT);
            List<Integer> rules = new ArrayList<>();
            for(String valueString : valueStrings){
                rules.add(Integer.parseInt(valueString));
            }
            stringListHashMap.put(ruleValue, rules);
        }
        return stringListHashMap;

    }

}
